<?php

/**
 * @author Mr Tuan - richdad.tx@gmail.com
 * @copyright 2012
 */
 
 
ini_set ('soap.wsdl_cache_enabled',0);
class ServiceInetController extends Controller
{
    public function actions()
    {
       return array(
        'MOReceiver' => array(
          'class' => 'CWebServiceAction',

        ),
      );
    }     
        
     /**
     * @param string $userId  
     * @param string $serviceId 
     * @param string $request_id 
     * @param string $command_code
     * @param string $info
     * @param string $user 
     * @param string $pass
     * @return string
     * @soap
     */
    
    function MOReceiver($userId,$serviceId,$request_id,$command_code,$info,$user,$pass)
    {	
    $result = -1;//loi he thong
    if(strcasecmp(trim($user),'canhsong')==0){
	   if(strcasecmp(trim($pass),'123456')==0){    
            $vInfor = explode(' ',trim($info));
            if(strcasecmp($vInfor[0],'CS')==0){
                if(strcasecmp($serviceId,'8041')==0){
                    if(!is_numeric($userId) ){
                       if(!startsWith($userId,'84')){
                         $result = 1; 
                       } 
                       //vitri tham so sai dinh dang
                	}else{
                	    if(!is_numeric($request_id)){
             	          $result = 3;
                       //vitri tham so sai dinh dang
                    	}else{
                    	  //xy ly noi dung tin nhan(MO) gui toi tu KH
                     /*   $model=new Users;
                        $model->username = $userId;
                        $model->password = Users::model()->encrypt($userId) ;
                        $model->create_time = new CDbExpression('NOW()');
                        $model->update_time = new CDbExpression('NOW()');
                        $model->last_visit_time = new CDbExpression('NOW()');
                        
                        if($model->save()){
                       		echo "0|1|Cam on ".$userId." da su dung dich vu tren dau so ".$serviceId." vui long dang nhap voi user va pass la sdt ban";
                        }else {
                            echo "not save";
                        }*/
                           $message = 'Cam on ban da su dung dich vu CS.';
                           $messageType = '0';
                           $contentType = '0';
                           $userInet = ''; //: iNET se cung cap cho ban
                           $passInet = ''; //: iNET se cung cap cho ban
                           //sendMT($userId,$serviceId,$request_id,$command_code,$message,$messageType,$contentType,$userInet,$passInet);
                           $result=0;
                    	}
                	}
                    
                }else{ //sai $serviceId = 8041
                   $result = 2; 
                }   
                            
            }else{
                $result = 4;
            }
            
        }else{//sai $pass
            $result = 6;
        }      
	}else{//sai $user
	   $result = 5;
	}
    return $result;
}


   public function actionInet(){
        ini_set('display_errors','on');
        $wsdl = 'http://canhsong.com/Index.php/serviceInet/MOReceiver';
        $client = new SoapClient($wsdl);
        echo $client->MOReceiver("84988142889","8385","0","XOSO","XOSO TEST","partner","partner@123");
		print_r($client);
		echo $client->__getLastRequest();
		echo $client->__getLastResponse();

        exit ;
    
   }
   
}